package com.hzqy.service.picture;

import java.io.File;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.commons.utils.FileUtils;
import com.hzqy.commons.utils.PublicUtil;
import com.hzqy.commons.utils.UploadImgUtil;
import com.hzqy.persistence.dao.picture.PictureDao;
import com.hzqy.web.vo.CmPicturesRelationVo;
import com.hzqy.web.vo.CmPicturesVo;

@Service
public class PictureServiceBean {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private PictureDao pictureDao;

	public List<CmPicturesRelationVo> picturesRelationSelectList(String picType) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("picType", picType);
		return pictureDao.picturesRelationSelectList(map);
	}
	public List<CmPicturesRelationVo> yhPicturesRelationSelectList() {
		return pictureDao.yhPicturesRelationSelectList();
	}


	public String uploadPictures(File uploadify, String uploadifyFileName, int f_cp_relationid, String picType ,String picLeftFile) {
		//增加了imgFile变量的前缀PIC/，因为所有的图片需要放到另一个工程中，要做一个分类。有可能会影响环球剧场，注意
		String imgFile = "PIC/imgs/upload/"+PictureType.getPicType(picType)+"/"+PublicUtil.getCurDate()+"/";
		String retu = UploadImgUtil.insertPic(uploadifyFileName, imgFile, uploadify,picLeftFile);
		return imgFile+retu;
	}

	public String getFilePath(String picType) {
		//增加了imgFile变量的前缀PIC/，因为所有的图片需要放到另一个工程中，要做一个分类。有可能会影响环球剧场，注意
		String imgFile = "PIC/imgs/upload/"+PictureType.getPicType(picType)+"/"+PublicUtil.getCurDate()+"/";
		return imgFile;
	}

	public String getFileName(String uploadifyFileName) {
		//Random random = new Random();
		SecureRandom random = new SecureRandom();
		int ranValue = random.nextInt(10000);
		String fileName = PublicUtil.getGenFileName()+ranValue+"."+FileUtils.getExtendName(uploadifyFileName);
		return fileName;
	}

	public List<CmPicturesVo> selectPictureList(Map<String,String> map) {
		return pictureDao.selectPictureList(map);
	}
	public List<CmPicturesVo> selectYHZPictureList(Map<String,String> map) {
		return pictureDao.selectYHZPictureList(map);
	}
}
